cmake_minimum_required(VERSION 2.8)
project(poseEstimate)

# 设置构建类型为Release以进行优化
set(CMAKE_BUILD_TYPE "Release")
add_definitions("-DENABLE_SSE")
#set(CMAKE_CXX_FLAGS "-std=c++11 -O2 ${SSE_FLAGS} -msse4")
set(CMAKE_CXX_FLAGS "-std=c++17 -O2 ${SSE_FLAGS} -msse4")


# 如果需要，可以添加自定义Find模块路径
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

# 查找所需的依赖包
find_package(OpenCV 4 REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(OpenGV) # 这个失败就不要设置成 REQUIRED
find_package(GTest REQUIRED)
find_package(Boost 1.75.0 COMPONENTS filesystem REQUIRED)

if(NOT OpenGV_FOUND)
    # 如果 OpenGV 没有找到，手动设置 include 目录和库文件路径
    set(OPENGV_INCLUDE_DIRS "/home/lee/opengv/include") # 手动设置 include dir
    set(OPENGV_LIBS "/home/lee/opengv/build/devel/lib/libopengv.so" "/home/lee/opengv/build/devel/lib/librandom_generators.so") 
endif()


# 包含依赖库的头文件目录
include_directories(
    ${PROJECT_SOURCE_DIR}/include
    ${PROJECT_SOURCE_DIR}/eval/calc
    ${PROJECT_SOURCE_DIR}/eval/utils
    ${PROJECT_SOURCE_DIR}/eval/alignment
    ${OpenCV_INCLUDE_DIRS}
    ${EIGEN3_INCLUDE_DIR}
    ${OPENGV_INCLUDE_DIRS}
    ${GTEST_INCLUDE_DIRS} 
    ${Boost_INCLUDE_DIRS}
    "/usr/include/eigen3/"
)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/..)

# 指定可执行文件及其依赖的源文件
add_library(${PROJECT_NAME} 
  src/poseEstimate.cpp
  eval/calc/ResultTrajectory.cpp
  eval/utils/Loader.cpp
  eval/utils/print.cpp
  eval/alignment/AlignTrajectory.cpp
  eval/alignment/AlignUtils.cpp
)
add_executable(${PROJECT_NAME}_test
  test/test_main.cpp
  test/Test.cpp
  )

# 链接所需的库
target_link_libraries(${PROJECT_NAME} 
    ${OpenCV_LIBS}
    ${OPENGV_LIBS}
    ${EIGEN3_LIBS}
    ${Boost_LIBRARIES}
)

target_link_libraries(${PROJECT_NAME}_test
    ${PROJECT_NAME}
    ${GTEST_LIBRARIES}
    pthread  # Google Test 需要线程支持
)
